#!/usr/bin/python
#
# Copyright (c) 2008, Mathias Weber
# Copyright (c) 2008, Thomas Stauffer
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id$

import sys
import functools

import direct.directbase.DirectStart

from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import DirectButton
from pandac.PandaModules import CardMaker, NodePath, TransparencyAttrib

base.setBackgroundColor(0.0, 0.0, 0.2)
base.disableMouse()

"""
Draw a flat quad with a constant size on aspect2d (The GUI also works on top of
aspect2d). Ideally the constant SIZE is 1.0. Make a it a little bit smaller to
see a small gap between the window border. This quad may help to see how the
Panda3D GUI works.
"""
SIZE = 1.0
card = CardMaker("Frame")
card.setFrame(-SIZE, SIZE, -SIZE, SIZE)
cardNode = NodePath(card.generate())
cardNode.setTexture(loader.loadTexture("grid.png"))
cardNode.reparentTo(aspect2d)

def buttonPressed(id):
    print "Button %s got pressed" % id

button_map = loader.loadModel("gui_button")

buttons = []
for i in range(5):
    # With egg-texture-cards.
    b = DirectButton(command=functools.partial(buttonPressed, i),
        relief=None, text="B %s" % i, text_scale=(0.5,0.5), text_pos=(0,-0.1),
        pos=(0, 1.0, (i-2)/10.0*-3), scale=0.2, pressEffect = 0,
        geom=(button_map.find("**/normal"), button_map.find("**/clicked"),
        button_map.find("**/hoover"), button_map.find("**/disabled")),
        geom_scale=(3.2,1.0,1.0))

    """
    # Loading images directly.
    b = DirectButton(command=functools.partial(buttonPressed, i),
        relief=None, text="B %s" % i, text_scale=(0.5,0.5), text_pos=(0,-0.1),
        pos=(0, 1.0, (i-2)/10.0*-3), scale=0.2, pressEffect = 0,
        geom=None,
        image=("gui_button_normal.png", "gui_button_clicked.png",
        "gui_button_hoover.png", "gui_button_disabled.png"),
        image_scale=(1.6,1.0,0.5),
    )
    b.setTransparency(TransparencyAttrib.MAlpha)
    """

    buttons.append(b)

def cleanGui():
    for button in buttons:
        button.remove()

base.accept("escape", sys.exit)
base.accept("a", render.analyze)
base.accept("o", base.oobe)
base.accept("d", cleanGui)

run()
